package com.lxhll.personnel.controller;

import com.lxhll.personnel.common.FileUtils;
import com.lxhll.personnel.core.ResponseData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class FileController {

    @PostMapping("/upload")
    public ResponseData upload(MultipartFile file) throws IOException {
        String newFileName= FileUtils.uploadPhoto(file);
        if(StringUtils.isBlank(newFileName)){
            return ResponseData.error("上传失败");
        }
        return ResponseData.ok(newFileName);
    }
}
